package com.example.demo.component;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 计划任务
 * **/
@Component
public class ScheduleRunner {
	
	private static final Logger logger = LogManager.getLogger(ScheduleRunner.class);

	// 服务开启刷新token
	private static boolean start_refresh_flag = false;
	private static final long startDelayTime = 60 * 1000;

	// 定时1.5小时刷新token
	private static final long delayTime = 2 * 60 * 1000;
	
	@Scheduled(fixedRate = startDelayTime)
    public void task_start() {
		if(!start_refresh_flag) {
			logger.info("ScheduleRunner task_start is running.");
			start_refresh_flag = true;
		}
    }
	
	@Scheduled(fixedRate = delayTime)
    public void task_refresh() {
		if(start_refresh_flag) {
			logger.info(Thread.currentThread() + ",ScheduleRunner task_refresh is running.");
		}
    }
}
